#! /bin/bash
set -eu

memory_mb=$(free -m | grep Mem: | awk '{print $2}')
sockets=$(lscpu | grep '^Socket(s):' | cut -d : -f 2 | awk '{print $1}')
cores_per_socket=$(lscpu | grep '^Core(s) per socket:' | cut -d : -f 2 | awk '{print $1}')
threads_per_core=$(lscpu | grep '^Thread(s) per core:' | cut -d : -f 2 | awk '{print $1}')

cat <<EOF
{
  "memory": {
    "total_mb": "${memory_mb}"
  },
  "cpu_topology": {
    "sockets": "${sockets}",
    "cores_per_socket": "${cores_per_socket}",
    "threads_per_core": "${threads_per_core}",
    "logical_cpus": "$(( sockets * cores_per_socket * threads_per_core ))"
  }
}
EOF
